package top.i51213.fastaction.action;

import android.content.Context;

public abstract class BaseActonComponent extends Action {
    private final Context context;
    private Data inputData;
    private Data outputData;

    public BaseActonComponent(Context context) {
        this.context = context;
    }

    @SuppressWarnings("unused")
    public Context getContext() {
        return context;
    }

    private boolean setInputData(Data data) {
        if (data.getDataType().hasIntent(getCurrentIntentType()) && data.getUris().size() > 0) {
            inputData = new Data(data.getDataType());
            inputData.addData(data);
            return true;
        }
        return false;
    }

    @SuppressWarnings("unused")
    public Data getInputData() {
        return inputData;
    }

    protected abstract Data makeOutputData();
    public Data getOutputData(){
        if(outputData==null){
            outputData=makeOutputData();
        }
        return outputData;
    }

    public abstract IntentType getCurrentIntentType();

    public abstract DataType getOutputDataType();

    @SuppressWarnings("unused")
    public boolean checkNext(BaseActonComponent next) {
        return getOutputDataType().hasIntent(next.getCurrentIntentType());
    }

    @SuppressWarnings("unused")
    public boolean feedNext(BaseActonComponent next) {
        boolean b=next.setInputData(getOutputData());
        if(next instanceof SameLast){
            next.makeOutputData();
        }
        return b;
    }
}
